package com.itboye.hutouben.activity.login;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutouben.R;
import com.itboye.hutouben.base.BaseActivity;
import com.itboye.hutouben.presenter.UserPresenter;
import com.itboye.hutouben.util.ByAlert;
import com.itboye.hutouben.util.IsUtilUid;
import com.itboye.hutouben.volley.ResultEntity;

import java.util.Observable;
import java.util.Observer;

/**
 * 忘记密码1
 */

public class PasswordOneActivity extends BaseActivity implements Observer {
    ImageView close_icon;// 返回图片
    TextView add_shap_title_tv;// 标题
    EditText passwprd_one_tel;
    TextView passwprd_one_ok;
    UserPresenter userPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.password_one_activity);
        add_shap_title_tv.setText("忘记密码");

        userPresenter=new UserPresenter(this);
    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close_icon:
                finish();
                break;
            case R.id.passwprd_one_ok:
//                if(!isMobileNO(passwprd_one_tel.getText().toString())){
//                    ByAlert.alert("请输入正确的电话号码！");
//                    return;
//                }
                if(passwprd_one_tel.getText().toString().length()!=11){
                    ByAlert.alert("请输入正确的电话号码！");
                    return;
                }
//                Intent intent=new Intent(this,PasswordTwoActivity.class);
//                intent.putExtra("phone", passwprd_one_tel.getText().toString());
//                startActivity(intent);
//                PasswordOneActivity.this.finish();
                showProgressDialog("请稍后...",true);
                userPresenter.sendVerificationCode("+86",passwprd_one_tel.getText().toString(),2+"");

                break;
            default:
                break;
        }
    }

    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity=handlerError(data);
        if(entity!=null){
            IsUtilUid.tianjia(entity);
            if(entity.getEventType()==UserPresenter.send_code_success){
                ByAlert.alert(entity.getData());
                Intent intent=new Intent(this,PasswordTwoActivity.class);
                intent.putExtra("phone", passwprd_one_tel.getText().toString());
                startActivity(intent);
                PasswordOneActivity.this.finish();
            }
            if(entity.getEventType()==UserPresenter.send_code_fail){
                ByAlert.alert(entity.getData());

            }
        }
        try {
            closeProgressDialog();
        } catch (Exception Exception) {
        }
    }
}
